package com.syni.mdd.yhd.common.all.dao.jpa;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.BmsDxNews;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BmsDxNewsDao extends BaseJPADao<BmsDxNews,Integer> {

    BmsDxNews findByBmsVideoIdAndParentTypeAndChildType(Integer videoId,Integer parentType,Integer childType);

    @Query(value="select bdn.* from bms_dx_news bdn where origin_role = 1 and bms_user_id = ?1" +
            " and update_time = (select max(update_time) from bms_dx_news " +
            "where parent_type = bdn.parent_type and origin_role = 1 and bms_user_id = ?1) group by bdn.update_time" +
            " order by bdn.update_time desc",nativeQuery=true)
    List<BmsDxNews> findUserClientOnceTypeTop(Integer userId);

    @Query(value="select bdn.* from bms_dx_news bdn where origin_role = ?1 and bms_business_id = ?2" +
            " and update_time = (select max(update_time) from bms_dx_news " +
            "where parent_type = bdn.parent_type and origin_role = ?1 and bms_business_id = ?2) group by bdn.update_time" +
            " order by bdn.update_time desc",nativeQuery=true)
    List<BmsDxNews> findBusinessTopNews(Integer roleId,Integer businessId);
}
